package com.bruce.asurada.service.impl;
import org.springframework.stereotype.Service;

import com.bruce.asurada.common.Result;
import com.bruce.asurada.common.dto.*;
import com.bruce.asurada.feign.UserServiceFeign;
import com.bruce.asurada.service.UserService;

import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;

@Service
@Slf4j
public class UserServiceImpl implements UserService{

    @Resource
    private UserServiceFeign userServiceFeign;


    /**
     * 用户注册
     */
    public boolean register(UserRegisterDto registerDto) throws Exception {
        Result<Void> result =userServiceFeign.register(registerDto);   
        if(null == result || !result.isSuccess()){
            throw new Exception("用户注册失败");
        } 
        log.info("用户注册成功: {}", registerDto);
        return result.isSuccess();
    }


     /**
     * 获取用户信息
     */
    public UserInfoDto getUserInfo(UserQueryDTO queryDTO) throws Exception {
        Result<UserInfoDto> result =userServiceFeign.getUserInfo(queryDTO);
        if(null == result || !result.isSuccess()){
            String message = null != result ? result.getMessage() : "用户信息获取失败";
            throw new Exception(message);
        }

        log.info("用户信息获取成功: {}", result.getData());
        return result.getData();
    }

}
